package com.yuqian.JavaSe.niuke;

public class Replacement {
    public static String replaceSpace(String iniString, int length) {
        // write code here
    	if(iniString==null||iniString.isEmpty()){
    		return iniString;
    	}
    	char[]a = iniString.toCharArray();
    	char[]b=new  char[length*3];
    	int j=-1;
    	for(int i=0;i<a.length;i++){
    		if(a[i]==' '){
    			b[++j]='%';
    			b[++j]='2';
    			b[++j]='0';
    		}else{
    			b[++j]=a[i];
    		}
    	}
    	return new String(b).substring(0, j+1);
    }
    
    public static void main(String[] args) {
		System.out.println(Replacement.replaceSpace("Mr John Smith", 13));
		System.out.println(Replacement.replaceSpace("Hello  World", 12));
	}
}
